package com.ztgf.commodity.api.client;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.ztgf.commodity.models.bo.CommodityUnitSaveBO;
import com.ztgf.commodity.models.dto.CommodityUnitDTO;
import com.ztgf.commodity.models.service.ICommodityUnitService;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * author: chenyu.wang
 * date: 2020-05-26 11:59
 * Description:
 */
@RestController
@RequestMapping("/api/commodityUnit")
@Slf4j
@Api(value = "CommodityUnitApiController", tags = "商品单位表接口")
public class CommodityUnitApiController {

    @DubboReference
    private ICommodityUnitService commodityApiUnitService;

    @PostMapping("/queryPageList")
    @ApiOperation(value = "商品单位列表", notes = "商品单位列表")
    public Result queryPageList() {
        Wrapper<CommodityUnitDTO> wrapper = new EntityWrapper<>();
        wrapper.eq("is_publish", 1);
        wrapper.eq("status", 0);
        wrapper.orderBy("sort", false);
        List<CommodityUnitDTO> list = commodityApiUnitService.selectList(wrapper);
        return new Result<>(list);
    }

    @PostMapping("/queryCategoryUnit")
    @ApiOperation(value = "查询商品类目单位", notes = "查询商品类目单位")
    public Result queryCategoryUnit(Long categoryId, Long brandId) {
        if (categoryId == null) {
            return new Result(CodeEnum.FAIL_100002);
        }
        return new Result<>(commodityApiUnitService.queryCategoryUnit(categoryId, brandId));
    }
}
